package entity

import "github.com/lab-online/internal/shared/valueobject"

type ClassOption func(*Class)

func NewClassEntity(opts ...ClassOption) ClassEntity {
	class := &Class{}
	class.UpdateEntity(opts...)
	return class
}

func (c *Class) UpdateEntity(opts ...ClassOption) {
	for _, opt := range opts {
		opt(c)
	}
}

func WithID(id uint) ClassOption {
	return func(c *Class) {
		c.ID = id
	}
}

func WithName(name string) ClassOption {
	return func(c *Class) {
		c.Name = name
	}
}

func WithDescription(description string) ClassOption {
	return func(c *Class) {
		c.Description = description
	}
}

func WithCourseID(courseID uint) ClassOption {
	return func(c *Class) {
		c.CourseID = courseID
	}
}

func WithTeacher(teacher string) ClassOption {
	return func(c *Class) {
		c.Teacher = &valueobject.User{
			Username: teacher,
		}
	}
}

func WithTeacherVO(teacher valueobject.UserVO) ClassOption {
	return func(c *Class) {
		c.Teacher = teacher
	}
}

func WithStudents(students ...string) ClassOption {
	return func(c *Class) {
		c.Students = make([]valueobject.UserVO, 0, len(students))
		AddStudents(students...)(c)
	}
}

func WithStudentVOs(students []valueobject.UserVO) ClassOption {
	return func(c *Class) {
		c.Students = students
	}
}
